#include "NeoLoadCircle.h"
#include "private/NeoLoadCirclePrivate.h"
#include <QParallelAnimationGroup>
#include <QPropertyAnimation>

NEO_PUBLIC_PROPERTY_CREATE_CPP(NeoLoadCircle, QColor, BackgroundColor)
NEO_PUBLIC_PROPERTY_CREATE_CPP(NeoLoadCircle, QColor, TrackColor)

NeoLoadCircle::NeoLoadCircle(QWidget *parent)
    : QWidget(parent), d_ptr(new NeoLoadCirclePrivate())
{
    NEO_PUBLIC_POINT(NeoLoadCircle)
    d->q_ptr = this;

    connect(d->pRotateAnimation, &QPropertyAnimation::valueChanged, this, [this]()
            { this->update(); });
}

NeoLoadCircle::~NeoLoadCircle() = default;

void NeoLoadCircle::start()
{
    NEO_PUBLIC_POINT(NeoLoadCircle)
    d->pAnimationGroup->start();
}

void NeoLoadCircle::stop()
{
    NEO_PUBLIC_POINT(NeoLoadCircle)
    d->pAnimationGroup->stop();
}

void NeoLoadCircle::paintEvent(QPaintEvent *event)
{
    NEO_PUBLIC_POINT(NeoLoadCircle)
    NEO_PAINTER_RESET
    d->drawBackground(&painter);
    d->drawTrack(&painter);
}